//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//********************************************************* 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.TridentWordAddIn.ResourceHelper;

namespace Microsoft.TridentWordAddIn.Presentation
{
    /// <summary>
    /// The class MessageBoxHelper 
    /// </summary>
    public sealed class MessageBoxHelper
    {
        private static string Header = ResourceFetcher.GetString("CaptionTridentWordAddIn");

        /// <summary>
        /// Initializes a new instance of the <see cref="MessageBoxHelper"/> class.
        /// </summary>
        private MessageBoxHelper()
        {
        }

        /// <summary>
        /// Shows the default.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>DialogResult</returns>
        public static DialogResult ShowDefault(string message)
        {
            return MessageBox.Show(
                  message,
                  Header,
                  MessageBoxButtons.OK,
                  MessageBoxIcon.Information);
        }

        /// <summary>
        /// Shows the default.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="icon">The icon.</param>
        /// <returns>DialogResult</returns>
        public static DialogResult ShowDefault(string message, MessageBoxIcon icon)
        {
            return MessageBox.Show(
                 message,
                 Header,
                 MessageBoxButtons.OK,
                 icon);
        }

        /// <summary>
        /// Shows the yes no.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>DialogResult</returns>
        public static DialogResult ShowYesNo(string message)
        {
            return MessageBox.Show(
                message,
                Header,
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button2);
        }

        /// <summary>
        /// Shows the yes no.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>DialogResult</returns>
        public static DialogResult ShowOkCancel(string message)
        {
            return MessageBox.Show(
                message,
                Header,
                MessageBoxButtons.OKCancel,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button2);
        }

        /// <summary>
        /// Shows the exception.
        /// </summary>
        /// <param name="ex">The ex.</param>
        /// <param name="owner">The owner.</param>
        public static void ShowException(Exception ex, IWin32Window owner)
        {
            if (owner == null)
            {
                ShowDefault(ex.Message, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show(
                   owner,
                   ex.Message,
                   Header,
                   MessageBoxButtons.OK,
                   MessageBoxIcon.Error);
            }
        }
    }
}
